package 二叉树;

import static java.lang.Math.max;

public class LC_104二叉树的最大深度 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public int maxDepth(TreeNode root) {
        //深度（结点到根的距离） && 高度（根到结点的距离）
        //后序遍历
        if(root==null) return 0;
        int leftheight=maxDepth(root.left);
        int rightheight=maxDepth(root.right);
        int height=1+max(leftheight,rightheight);
        return height;

        //return 1+max(maxDepth(root.left),maxDepth(root.right));
    }
}
